//
//  MQMessageCodeViewController.m
//  meiquan
//
//  Created by hejingjin on 2017/10/29.
//  Copyright © 2017年 mq. All rights reserved.
//

#import "MQMessageCodeViewController.h"
#import "NSString+Extension.h"
#import "MQmessagecodeviewss.h"
#import "MBProgressHUD+MJ.h"

@interface MQMessageCodeViewController ()

@property(nonatomic,strong)MQmessagecodeviewss *messagecodeview;

@end

@implementation MQMessageCodeViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    self.title = @"设置密码";
    
    [self setUpMainInterface];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)setUpMainInterface{
    
    
    self.view.backgroundColor = BSTColorFromRGB(0xefefef);
    
    _messagecodeview = [MQmessagecodeviewss loadMessageCodeViews];
    _messagecodeview.bst_x = 0;
    _messagecodeview.bst_y = 64;
    _messagecodeview.bst_width=BSTScreenW;
    _messagecodeview.bst_height = BSTScreenH - 64;
    
    _messagecodeview.flishButton.layer.cornerRadius = 4.f;
    _messagecodeview.flishButton.layer.masksToBounds = YES;
    [_messagecodeview.flishButton addTarget:self action:@selector(flishButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    
    [_messagecodeview.getmessagecodeButton addTarget:self action:@selector(getmessagecodeButtonPerssed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_messagecodeview];
}

-(void)flishButtonPressed:(UIButton *)sender{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    
    NSString *codestr = _messagecodeview.messagecodeFeild.text;
    NSString *password = _messagecodeview.passwordTextField.text;
    NSString *repassword = _messagecodeview.repasswordTextField.text;
    
    if ([NSString isBlankString:codestr]) {
        [iToastUtil displayMsg:@"请输入验证码"];
        return;
    }
    if ([NSString isBlankString:password]) {
        [iToastUtil displayMsg:@"请输入密码"];
        return;
    }
    if ([NSString isBlankString:repassword]) {
        [iToastUtil displayMsg:@"请输入确认密码"];
        return;
    }

    [MBProgressHUD showMessage:@"正在设置，请稍后..."];
    [param setValue:codestr forKey:@"phoneValid"];
    [param setValue:password forKey:@"password"];
    [param setValue:repassword forKey:@"repassword"];
    [param setValue:_phonestr forKey:@"telephone"];
    
    
    if (codestr.length !=6) {
         [iToastUtil displayMsgBytime:@"验证码长度不正确" duration:600];
        
    }else if (![password isEqualToString:repassword]){
         [iToastUtil displayMsgBytime:@"两次密码不一致" duration:600];
    }else{
        
        
        [MQRequestTools POSTWithMethod:registers params:param success:^(id json) {
            [MBProgressHUD hideHUD];
            [self.navigationController popToRootViewControllerAnimated:YES];
            
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUD];

              [iToastUtil displayMsgByLongtime:@"注册失败"];
        }];
    }
    
    
    
//    param setValue: forKey:@""];
    
    
    
    
}
-(void)getmessagecodeButtonPerssed:(UIButton *)sender{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    
    [param setValue:_phonestr forKey:@"telephone"];
    
    
    [MQRequestTools GETWithMethod:getmessage params:param success:^(id json) {
        
        NSLog(@"%@",json);
        
    } failure:^(NSError *error) {
        
    }];
    
    
    
}

@end
